#!/bin/bash

if [ $# -lt 1 ]; then
    return 1
fi
MIRROR=$1

## Set XX_VERSION=DISABLE to void building specified dependency
BOOST_VERSION=1_58_0
PROTOBUF_VERSION=2.6.1
SNAPPY_VERSION=1.1.3
SOFA_PBRPC_VERSION=1.1.3
ZOOKEEPER_VERSION=3.4.9
GFLAGS_VERSION=2.1.2
GLOG_VERSION=0.3.3
GTEST_VERSION=1.8.0
LIBUNWIND_VERSION=0.99
GPERFTOOLS_VERSION=2.5
INS_VERSION=0.15
NOSE_VERSION=1.3.7

if [ $MIRROR == "china" ]; then
    BOOST_URL=http://mirrors.tuna.tsinghua.edu.cn/macports/distfiles/boost/boost_${BOOST_VERSION}.tar.bz2
    PROTOBUF_URL=http://mirrors.163.com/gentoo/distfiles/protobuf-${PROTOBUF_VERSION}.tar.bz2
    SNAPPY_URL=http://mirrors.163.com/gentoo/distfiles/snappy-${SNAPPY_VERSION}.tar.gz
    SOFA_PBRPC_URL=https://github.com/baidu/sofa-pbrpc/archive/v${SOFA_PBRPC_VERSION}.tar.gz
    ZOOKEEPER_URL=http://mirrors.163.com/gentoo/distfiles/zookeeper-${ZOOKEEPER_VERSION}.tar.gz
    GFLAGS_URL=https://github.com/schuhschuh/gflags/archive/v${GFLAGS_VERSION}.tar.gz
    GLOG_URL=https://github.com/google/glog/archive/v${GLOG_VERSION}.tar.gz
    GTEST_URL=https://github.com/google/googletest/archive/release-${GTEST_VERSION}.tar.gz
    LIBUNWIND_URL=http://repository.timesys.com/buildsources/l/libunwind/libunwind-${LIBUNWIND_VERSION}/libunwind-${LIBUNWIND_VERSION}.tar.gz
    GPERFTOOLS_URL=https://github.com/00k/gperftools/raw/master/gperftools-${GPERFTOOLS_VERSION}.tar.gz
    INS_URL=https://github.com/baidu/ins/archive/${INS_VERSION}.tar.gz
    NOSE_URL=http://mirrors.163.com/gentoo/distfiles/nose-${NOSE_VERSION}.tar.gz
elif [ $MIRROR == "origin" ]; then
    BOOST_URL=http://downloads.sourceforge.net/project/boost/boost/1.58.0/boost_${BOOST_VERSION}.tar.bz2
    PROTOBUF_URL=https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/protobuf-${PROTOBUF_VERSION}.tar.bz2
    SNAPPY_URL=https://github.com/google/snappy/releases/download/${SNAPPY_VERSION}/snappy-${SNAPPY_VERSION}.tar.gz
    SOFA_PBRPC_URL=https://github.com/baidu/sofa-pbrpc/archive/v${SOFA_PBRPC_VERSION}.tar.gz
    ZOOKEEPER_URL=http://www-us.apache.org/dist/zookeeper/zookeeper-${ZOOKEEPER_VERSION}/zookeeper-${ZOOKEEPER_VERSION}.tar.gz
    GFLAGS_URL=https://github.com/schuhschuh/gflags/archive/v${GFLAGS_VERSION}.tar.gz
    GLOG_URL=https://github.com/google/glog/archive/v${GLOG_VERSION}.tar.gz
    GTEST_URL=https://github.com/google/googletest/archive/release-${GTEST_VERSION}.tar.gz
    LIBUNWIND_URL=http://download.savannah.gnu.org/releases/libunwind/libunwind-${LIBUNWIND_VERSION}.tar.gz
    GPERFTOOLS_URL=https://github.com/gperftools/gperftools/releases/download/gperftools-${GPERFTOOLS_VERSION}/gperftools-${GPERFTOOLS_VERSION}.tar.gz
    INS_URL=https://github.com/baidu/ins/archive/${INS_VERSION}.tar.gz
    NOSE_URL=https://pypi.python.org/packages/58/a5/0dc93c3ec33f4e281849523a5a913fa1eea9a3068acfa754d44d88107a44/nose-${NOSE_VERSION}.tar.gz
elif [ $MIRROR == "baidu" ]; then
    BOOST_URL=http://gitlab.baidu.com/baidups/third/raw/master/boost_${BOOST_VERSION}.tar.bz2
    PROTOBUF_URL=http://gitlab.baidu.com/baidups/third/raw/master/protobuf-${PROTOBUF_VERSION}.tar.bz2
    SNAPPY_URL=http://gitlab.baidu.com/baidups/third/raw/master/snappy-${SNAPPY_VERSION}.tar.gz
    SOFA_PBRPC_URL=http://gitlab.baidu.com/baidups/third/raw/master/sofa-pbrpc-${SOFA_PBRPC_VERSION}.tar.gz
    ZOOKEEPER_URL=http://gitlab.baidu.com/baidups/third/raw/master/zookeeper-${ZOOKEEPER_VERSION}.tar.gz
    GFLAGS_URL=http://gitlab.baidu.com/baidups/third/raw/master/gflags-${GFLAGS_VERSION}.tar.gz
    GLOG_URL=http://gitlab.baidu.com/baidups/third/raw/master/glog-${GLOG_VERSION}.tar.gz
    GTEST_URL=http://gitlab.baidu.com/baidups/third/raw/master/googletest-release-${GTEST_VERSION}.tar.gz
    LIBUNWIND_URL=http://gitlab.baidu.com/baidups/third/raw/master/libunwind-${LIBUNWIND_VERSION}.tar.gz
    GPERFTOOLS_URL=http://gitlab.baidu.com/baidups/third/raw/master/gperftools-${GPERFTOOLS_VERSION}.tar.gz
    INS_URL=http://gitlab.baidu.com/baidups/third/raw/master/ins-${INS_VERSION}.tar.gz
    NOSE_URL=http://gitlab.baidu.com/baidups/third/raw/master/nose-${NOSE_VERSION}.tar.gz
else
    return 1
fi

